package com.badibadi.adapter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.badibadi.activity.InformActivity;
import com.badibadi.adapter.PinLunAdapter.PinLunInterface;
import com.badibadi.adapter.PinLunAdapter.ViewHolder;
import com.badibadi.adapter.PinLunAdapter.ij;
import com.badibadi.infos.AtModel;
import com.badibadi.infos.Discuss;
import com.badibadi.infos.Results;
import com.badibadi.infos.ShowDisscussModel;
import com.badibadi.mytools.AsyncLoadNetworkPic;
import com.badibadi.mytools.CalendarTools;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.EditTextTools;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.SinaExpressionTools;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 该适配器适用于showDisscuss接口
 * 
 * @author Administrator
 * 
 */
public class PinLunGYAdapter extends BaseAdapter {
	boolean KeyBoardIsOpen;
	InputMethodManager imm;
	/**
	 * 个人+俱乐部回复评论---post
	 * 
	 * @param $uid
	 *            ;//评论者的id
	 * @param $re_uid
	 *            ;//被回复的用户id
	 * @param $table
	 *            ;// 被评论类型activity club humor_trends photo photo_img
	 *            record_article
	 * @param $cid
	 *            ;//回复评论是评论的那个内容的id
	 * @param $rid
	 *            ;//回复的那个评论ID
	 * @param $first_discussId
	 *            ;//回复的评论的最上层ID(始终是1级评论用户的id)
	 * @param $message
	 *            ;//回复的内容
	 */
	/**
	 * 这里是活动对应活动id
	 */
	String actId;
	String table;// * @param $table ;// 被评论类型activity club humor_trends photo
					// photo_img record_article
	// 发起者的id，可以是活动发起者，（意思就是可以有最高权限，能够删除评论人的）
	private String faqizheId;

	private static final String TAG = "PinLunGYAdapter";
	private Context context;
	// private Discuss discuss;
	private List<ShowDisscussModel> mlist;
	List<ij> panduan;
	private DisplayImageOptions options;
	private PinLunInterface pinLunInterface;// 刷新接口

	private EditText send_content;// 文本框
	private Button send;// 发送按钮
	// replyDiscuss(replyDiscuss(re_uid, rid, first_discussId, message););
	// 下面的是回复的
	// private boolean is_yiji;//判断是一级评论还是2级评论//仅用于回复
	private String re_uid;// 被回复的用户的id；
	private String rid;// 回复的那个评论的id
	private String first_discussId;// 回复的评论的最上层ID(始终是1级评论用户的id)
	public static final int BIAO_QING = 33;

	PinLunRefreshMsg pinLunRefreshMsg;
	PinLunRefreshMsg pinLunRefreshMsg_1;
	LinearLayout activityRootView;
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_net_error));
				} catch (Exception e) {
				}
				break;
			case 2:// 删除成功

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_xb55));
					if (pinLunRefreshMsg_1 != null) {
						pinLunRefreshMsg_1.RefreshMsgNum();
					}
					if (pinLunInterface != null) {
						pinLunInterface.DeletePingLunRefresh();
					}

				} catch (Exception e) {

				}
				break;
			case 3:

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.SystemError));
				} catch (Exception e) {

				}

				break;
			case 4:// 删除失败

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_xb121));
				} catch (Exception e) {

				}
				break;
			case 5:// 回复

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_xb55));
					send_content.setText("");
					if (pinLunRefreshMsg != null) {
						pinLunRefreshMsg.RefreshMsgNum();
					}
					if (pinLunInterface != null) {
						pinLunInterface.DeletePingLunRefresh();
					}

				} catch (Exception e) {

				}
				break;
			case 6:// 回复失败

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_xb113));
				} catch (Exception e) {

				}
				break;
			case 7:// 评论成功

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_xb55));

					send_content.setText("");
					// Intent intent=new
					// Intent(getActivity(),LogReadingDanjiActivity.class);
					// // bun.putString("aid", aid);
					// // bun.putInt("position", position);
					// // bun.putString("rid", rid);
					// intent.put("aid", value);
					// intent.put("position",position);
					if (pinLunRefreshMsg != null) {
						pinLunRefreshMsg.RefreshMsgNum();
					}
					if (pinLunInterface != null) {
						pinLunInterface.DeletePingLunRefresh();
					}

				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 8:// 评论成功

				try {
					Utils.ExitPrgress(context);
					Utils.showMessage(context, context.getResources()
							.getString(R.string.l_xb113));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			default:
				break;
			}
		}
	};

	public void openOr_Close() {
		if (activityRootView != null)
			activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
					new OnGlobalLayoutListener() {
						private int preHeight = 0;

						@Override
						public void onGlobalLayout() {
							// 这里获取的activityRootView.getRootView().getHeight()
							// 是根视图，根视图不会变化
							//
							// " activityRootView.getRootView().getHeight()-->"
							// + activityRootView.getRootView()
							// .getHeight());
							// 这里获取的activityRootView.getHeight()
							// 是View的高,高是根据键盘压缩会发生变化
							//
							// + activityRootView.getHeight());
							int heightDiff = activityRootView.getRootView()
									.getHeight() - activityRootView.getHeight();
							// ("height differ = " +
							// heightDiff);
							// 在数据相同时，减少发送重复消息。因为实际上在输入法出现时会多次调用这个onGlobalLayout方法。
							if (preHeight == heightDiff) {
								return;
							}
							preHeight = heightDiff;
							//

							// 这里的200可能会根据不同的手机来适应不同的
							if (heightDiff > 200) {
								// ("input method shown!");
								// Toast.makeText(context, "键盘已经打开",
								// Toast.LENGTH_SHORT).show();
								KeyBoardIsOpen = true;
							} else {
								// Toast.makeText(context, "键盘已经关闭",
								// Toast.LENGTH_SHORT).show();
								KeyBoardIsOpen = false;
							}
						}

					});
	}

	public PinLunGYAdapter(final Context context, Discuss discuss,
			String actId, String table, String fabuzheId,
			final EditText send_content, Button send) {
		this.actId = actId;
		this.table = table;
		this.faqizheId = fabuzheId;
		this.send_content = send_content;
		this.send = send;
		// try {
		// this.activityRootView=(LinearLayout)((Activity)context).findViewById(R.id.activityRootView);
		// openOr_Close();
		// } catch (Exception e) {
		// // TODO: handle exception
		// }

		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();

		this.context = context;
		if (this.send != null)
			this.send.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (!Utils.getUid(context).equals("")) {
						if (send_content != null) {
							if (!send_content.getText().toString().trim()
									.equals("")) {
								if (send_content
										.getHint()
										.toString()
										.indexOf(
												context.getResources()
														.getString(
																R.string.l_xb161)) != -1) {
									// replyDiscuss(replyDiscuss(re_uid, rid,
									// first_discussId, message););
									replyDiscuss(re_uid, rid, first_discussId);
									send_content.setHint(context.getResources()
											.getString(R.string.l_xb162));
								} else {

									sendMessage();
								}

							}
						}
					} else {
						Utils.showMessage(context, context.getResources()
								.getString(R.string.l_xb10));
					}
				}
			});
		// this.discuss=discuss;
		mlist = discuss.getDiscu();
		panduan = new ArrayList<PinLunGYAdapter.ij>();
		if (mlist != null)

			for (int i = 0; i < mlist.size(); i++) {
				ij m = new ij();
				m.i = i;
				m.j = 0;
				//
				panduan.add(m);
				if (mlist.get(i).getComment() != null) {
					// 统计数量
					// num=num+(mlist.get(i).getTwo().size());
					for (int j = 0; j < mlist.get(i).getComment().size(); j++) {
						ij m1 = new ij();
						m1.i = i;
						m1.j = j + 1;
						panduan.add(m1);
						//
					}
				}
			}

	}

	@Override
	public int getItemViewType(int position) {

		if (panduan.get(position).j == 0) {
			return 0;
		} else if (panduan.get(position).j != 0) {
			return 1;
		}

		return 0;
	}

	@Override
	public int getViewTypeCount() {

		return 3;
	}

	@Override
	public int getCount() {

		return panduan.size();
	}

	@Override
	public Object getItem(int position) {

		return null;
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = LayoutInflater.from(context);
		int type = getItemViewType(position);
		ViewHolder holder = new ViewHolder();
		if (convertView == null) {
			if (type == 0) {
				convertView = inflater.inflate(R.layout.pinglun_0, null);
				holder.head = (ImageView) convertView.findViewById(R.id.head);
				holder.message = (TextView) convertView
						.findViewById(R.id.message);
				holder.nickName = (TextView) convertView
						.findViewById(R.id.nickName);
				holder.post_time = (TextView) convertView
						.findViewById(R.id.post_time);
				holder.set = (ImageView) convertView.findViewById(R.id.set);
			} else if (type == 1) {
				convertView = inflater.inflate(R.layout.pinglun_1, null);
				holder.head = (ImageView) convertView.findViewById(R.id.head);
				holder.message = (TextView) convertView
						.findViewById(R.id.message);
				holder.nickName = (TextView) convertView
						.findViewById(R.id.nickName);
				holder.post_time = (TextView) convertView
						.findViewById(R.id.post_time);
				holder.set = (ImageView) convertView.findViewById(R.id.set);
				holder.to_nickName = (TextView) convertView
						.findViewById(R.id.to_nickName);
			}
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (type == 0) {
			int i = panduan.get(position).i;
			int j = panduan.get(position).j - 1;
			// holder.message.setText(""+mlist.get(i).getMessage());
			new HtmlUtils(context, holder.message, ""
					+ mlist.get(i).getMessage()).showTextView();
			holder.nickName.setText("" + mlist.get(i).getNickName());

			//
			String posttime = CalendarTools.getFormatTime(
					Double.parseDouble(mlist.get(i).getPost_time() + "000"),
					"yyyy.MM.dd HH:mm");

			holder.post_time.setText(posttime);
			try {
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl + "/" + mlist.get(i).getHead()
								+ Constants.appPhoto4img, holder.head, options);
			} catch (Exception e) {

			}

			setPopWindow(holder.set, mlist.get(i).getId(), true, i, j,
					mlist.get(i));

		}
		if (type == 1) {
			int i = panduan.get(position).i;
			int j = panduan.get(position).j - 1;

			// holder.message.setText(Html.fromHtml(""+mlist.get(i).getComment().get(j).getMessage()),new
			// NetworkImageGetter(),null);
			// holder.message.setText(""+mlist.get(i).getComment().get(j).getMessage());
			new HtmlUtils(context, holder.message, ""
					+ mlist.get(i).getComment().get(j).getMessage())
					.showTextView();
			holder.nickName.setText(""
					+ mlist.get(i).getComment().get(j).getUser().getNickName());
			// String
			// posttime=CalendarTools.getFormatTime(Double.parseDouble(mlist.get(i).getPost_time()+"000"),
			// "yyyy.MM.dd HH.mm");
			String posttime = CalendarTools.getFormatTime(
					Double.parseDouble(mlist.get(i).getPost_time() + "000"),
					"yyyy.MM.dd HH:mm");
			holder.post_time.setText("" + posttime);
			holder.to_nickName.setText(""
					+ mlist.get(i).getComment().get(j).getTo_user()
							.getNickName());
			try {
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ "/"
								+ mlist.get(i).getComment().get(j).getUser()
										.getHead() + Constants.appPhoto4img,
						holder.head, options);
			} catch (Exception e) {

			}
			setPopWindow(holder.set, mlist.get(i).getComment().get(j).getId(),
					false, i, j, mlist.get(i));
		}
		return convertView;
	}

	// /**
	// * 网络图片
	// * @author Susie
	// */
	// public class NetworkImageGetter implements Html.ImageGetter{
	//
	// TextView mTvThree;
	// public NetworkImageGetter(TextView tv)
	// {
	// mTvThree=tv;
	//
	// }
	// @Override
	// public Drawable getDrawable(String source) {
	//
	// Drawable drawable = null;
	// // 封装路径
	// File file = new File(Environment.getExternalStorageDirectory(),
	// "badibadi");
	// // 判断是否以http开头
	// if(source.startsWith("http")) {
	// // 判断路径是否存在
	// if(file.exists()) {
	// // 存在即获取drawable
	// drawable = Drawable.createFromPath(file.getAbsolutePath());
	// drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
	// drawable.getIntrinsicHeight());
	// } else {
	// // 不存在即开启异步任务加载网络图片
	// // AsyncLoadNetworkPic networkPic = new AsyncLoadNetworkPic();
	// AsyncLoadNetworkPic networkPic=new AsyncLoadNetworkPic(source, mTvThree,
	// new NetworkImageGetter(mTvThree));
	// networkPic.execute(source);
	// }
	// }
	// return drawable;
	// }
	// }

	/**
	 * 回复，举报和删除按钮
	 * 
	 * @param v
	 *            pop要显示在v下面
	 * @param uid
	 *            ---(必需)操作删除的用户ID
	 * @param id
	 *            (必需)要删除的评论的ID
	 * @param isPinlun
	 *            要删除的是否是评论的消息，如果不是就是回复
	 * 
	 * @param i
	 *            ;用于判断是要取哪条数据
	 * @param j
	 *            ;用于判断是要取哪条数据
	 * 
	 * 
	 */
	private void setPopWindow(View view, final String id,
			final boolean isPinlun, final int i, final int j,
			final ShowDisscussModel disscuss) {
		View root = LayoutInflater.from(context).inflate(R.layout.popwindow0,
				null);
		final PopupWindow popup = new PopupWindow(root, DisplayUtil.dip2px(
				context, 50), DisplayUtil.dip2px(context, 100));
		// 回复
		root.findViewById(R.id.huifu).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!Utils.getUid(context).equals("")) {

							if (isPinlun == true)// 如果回复的是评论
							{
								re_uid = mlist.get(i).getUid();
								rid = mlist.get(i).getId();
								first_discussId = mlist.get(i).getId();
								send_content.setHint(context.getResources()
										.getString(R.string.l_xb161)
										+ mlist.get(i).getNickName() + ":");
								send_content.setText("");

								// EditTextTools.ConsultingEvaluation(send_content);
								// EditTextTools.ConsultingEvaluation(send_content,
								// 500);
								// replyDiscuss(mlist.get(i).getUid(),
								// mlist.get(i).getId(), mlist.get(i).getId());
								// send_content.setFocusable(true);
								// send_content.setFocusableInTouchMode(true);
								// send_content.requestFocus();
								// send_content.requestFocusFromTouch();
								EditTextTools.getFocusable(send_content);
								EditTextTools
										.CloseOrConsultingEvaluation(send_content);
								if (popup != null) {
									popup.dismiss();
								}

							} else// 如果回复的是别人的回复
							{
								// is_yiji=false;
								re_uid = mlist.get(i).getComment().get(j)
										.getUid();
								rid = mlist.get(i).getComment().get(j).getId();
								first_discussId = mlist.get(i).getId();
								send_content.setHint(context.getResources()
										.getString(R.string.l_xb161)
										+ mlist.get(i).getComment().get(j)
												.getUser().getNickName() + ":");
								send_content.setText("");
								// EditTextTools.ConsultingEvaluation(send_content,
								// 500);
								// replyDiscuss(Utils.getUid(context), re_uid,
								// table, cid, rid, first_discussId, message);
								// send_content.setFocusable(true);
								// send_content.setFocusableInTouchMode(true);
								// send_content.requestFocus();
								// send_content.requestFocusFromTouch();
								EditTextTools.getFocusable(send_content);
								EditTextTools
										.CloseOrConsultingEvaluation(send_content);
								if (popup != null) {
									popup.dismiss();
								}

							}
						} else {
							Utils.showMessage(context, context.getResources()
									.getString(R.string.l_xb10));
						}
					}
				});
		root.findViewById(R.id.jubao).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!Utils.getUid(context).equals("")) {
							if (isPinlun == true)// 如果是评论
							{
								Intent intent = new Intent(context,
										InformActivity.class);
								intent.putExtra("bei_person_id", mlist.get(i)
										.getUid());// 被举报人的内容的所属用户ID;
								intent.putExtra("table", "discuss");
								intent.putExtra("bei_cid", "0");
								intent.putExtra("bei_neirong_id", mlist.get(i)
										.getId());// 内容id
								context.startActivity(intent);

								((Activity) context).overridePendingTransition(
										R.anim.slide_left, R.anim.slide_right);
							} else// 如果是回复
							{
								Intent intent = new Intent(context,
										InformActivity.class);
								intent.putExtra("bei_person_id", mlist.get(i)
										.getComment().get(j).getUser().getId());// 被举报人的内容的所属用户ID;
								intent.putExtra("table", "discuss");
								intent.putExtra("bei_cid", "0");
								intent.putExtra("bei_neirong_id", mlist.get(i)
										.getComment().get(j).getId());// 内容id
								context.startActivity(intent);

								((Activity) context).overridePendingTransition(
										R.anim.slide_left, R.anim.slide_right);
							}
						} else {
							Utils.showMessage(context, context.getResources()
									.getString(R.string.l_xb10));
						}

					}
				});
		// 删除评论
		root.findViewById(R.id.shanchu).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!Utils.getUid(context).equals("")) {
							// commonality/deleteDiscuss
							if (isPinlun == true) {
								// 判断发布活动的人是否是操作的人
								if (faqizheId != null) {
									if (faqizheId.equals(""
											+ Utils.getUid(context))) {
										deleteDiscuss(id);
									} else {
										Utils.showMessage(
												context,
												context.getResources()
														.getString(
																R.string.l_xb121));
									}
								} else {
									Utils.showMessage(
											context,
											context.getResources().getString(
													R.string.l_xb121));
								}
							} else// 删除回复还没有这接口
							{
								// 判断发布活动的人是否是操作的人
								if (faqizheId.equals("" + Utils.getUid(context))) {
									deleteDiscuss(id);
								} else {
									Utils.showMessage(
											context,
											context.getResources().getString(
													R.string.l_xb121));
								}
							}
							if (popup != null)
								popup.dismiss();
						} else {
							Utils.showMessage(context, context.getResources()
									.getString(R.string.l_xb10));
						}
					}
				});
		//
		popup.setBackgroundDrawable(new BitmapDrawable());
		popup.setFocusable(true);
		popup.setTouchable(true);
		popup.setOutsideTouchable(true);
		view.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				popup.showAsDropDown(v);
			}
		});
	}

	// TODO Auto-generated method stub
	// 删除评论
	/**
	 * 个人+俱乐部操作删除评论---》》
	 * 调用该接口之前需要注意：个人时，仅有自己（自己发布的内容的评论）有该权限删除；俱乐部时，自己（自己发布的内容的评论）和管理员都有权限删除 post
	 * 
	 * @param $uid
	 *            ---(必需)操作删除的用户ID
	 * @param $id
	 *            , //(必需)要删除的评论的ID
	 */
	public void deleteDiscuss(final String id) {
		// deleteDiscuss
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				List<AtModel> list = new ArrayList<AtModel>();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", Utils.getUid(context));
				map.put("id", id);
				String invite_content = Utils.sendRequest(map,
						Constants.BadiUrl_1 + "commonality/deleteDiscuss");
				//
				if (invite_content != null) {
					Results results = Utils.checkResult_NNN(context,
							invite_content);
					if (results != null && !results.getRetmsg().equals("null")) {
						// ("解析出来的数据:" + results.getRetmsg());
						try {
							// sd
							if (results.isRet() == true)
								handler.sendEmptyMessage(2);
							else
								handler.sendEmptyMessage(4);
						} catch (Exception e) {

						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}

			}
		});

	}

	// TODO Auto-generated method stub
	/**
	 * @param $re_uid
	 *            ;//被回复的用户id
	 * @param rid
	 *            ;//回复的那个评论ID
	 * @param first_discussId
	 *            //回复的评论的最上层ID(始终是1级评论用户的id)
	 * @param message
	 *            //回复的内容
	 */
	public void replyDiscuss(final String re_uid, final String rid,
			final String first_discussId) {
		/*
		 * 个人+俱乐部回复评论---post
		 * 
		 * @param $uid;//评论者的id
		 * 
		 * @param $re_uid;//被回复的用户id
		 * 
		 * @param $table ;// 被评论类型activity club humor_trends photo photo_img
		 * record_article
		 * 
		 * @param $cid;//回复评论是评论的那个内容的id (这里是活动的id)
		 * 
		 * @param $rid;//回复的那个评论ID
		 * 
		 * @param $first_discussId;//回复的评论的最上层ID(始终是1级评论用户的id)
		 * 
		 * @param $message;//回复的内容
		 */
		final String message = this.send_content.getText().toString().trim();

		final String msg = SinaExpressionTools.replaceAllReplaceToPath(message);

		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				List<AtModel> list = new ArrayList<AtModel>();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", Utils.getUid(context));// (╯‵□′)╯︵┻━┻
				map.put("re_uid", re_uid);
				map.put("table", table);
				map.put("cid", actId);
				map.put("rid", rid);
				map.put("first_discussId", first_discussId);
				map.put("message", msg);
				String invite_content = Utils.sendRequest(map,
						Constants.BadiUrl_1 + "commonality/replyDiscuss");
				//
				if (invite_content != null) {
					Results results = Utils.checkResult_NNN(context,
							invite_content);
					if (results != null && !results.getRetmsg().equals("null")) {
						// ("解析出来的数据:" + results.getRetmsg());
						try {
							// sd
							if (results.isRet() == true)
								handler.sendEmptyMessage(5);
							else
								handler.sendEmptyMessage(6);
						} catch (Exception e) {

						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	class ij {
		public int i;// 第几组
		public int j;// 第i组的j-1列

		@Override
		public String toString() {
			return "ij [i=" + i + ", j=" + j + "]";
		}
	}

	public void setOnRefreshPingLunInterface(PinLunInterface refresh) {
		pinLunInterface = refresh;
	}

	// 用来刷新显示评论数量的接口，成功后+1
	public void setOnRefreshMsgNum(PinLunRefreshMsg refresh) {
		pinLunRefreshMsg = refresh;
	}

	// 用来刷新显示评论数量的接口，成功后-1
	public void setOnRefreshMsgNum_1(PinLunRefreshMsg refresh) {
		pinLunRefreshMsg_1 = refresh;
	}

	public interface PinLunInterface {
		void DeletePingLunRefresh();// 删除评论后刷新(但是所有刷新操作都在用他)
		// void sendPingLunRefresh();//发送评论后刷新
	}

	public interface PinLunRefreshMsg {
		void RefreshMsgNum();
	}

	public void sendMessage() {
		//
		// + send_content.getText().toString());
		sendMessage(Utils.getUid(context), faqizheId, actId, table,
				send_content.getText().toString().trim());
	}

	/**
	 * 被评论类型activity club humor_trends photo photo_img record_article 用户评论使用接口
	 * 提交方式GET
	 * 
	 * @param $uid
	 *            ;//评论者的id @param $buid;//被评论者的id
	 * @param $conId
	 *            ;//被评论的内容id @param $type ;// 被评论类型activity club humor_trends
	 *            photo photo_img record_article
	 * @param $content
	 *            ;//评论内容
	 */
	public void sendMessage(final String uid, final String buid,
			final String conId, final String type, final String contents) {
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				//
				// + conId + "&type=" + type + "&content=" + contents);
				// String content = Utils.getRequest(Constants.BadiUrl
				// + "user_discuss?uid=" + uid + "&buid=" + buid
				// + "&conId=" + conId + "&type=" + type + "&content="
				// + contents);
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", uid);
				map.put("buid", buid);
				map.put("conId", conId);
				map.put("type", type);
				String content3 = SinaExpressionTools
						.replaceAllReplaceToPath(contents);
				map.put("content", content3);
				String content = Utils.sendRequest(map, Constants.BadiUrl
						+ "user_discuss");

				if (content != null) {
					// ("数据是：" + content);
					Results results = Utils.checkResult_NNN(context, content);
					if (results != null && !results.getRetmsg().equals("null")) {
						//
						try {

							if (results.isRet() == true) {
								handler.sendEmptyMessage(7);
							} else {
								handler.sendEmptyMessage(8);
							}
						} catch (Exception e) {
							// TODO Auto-generated catch block

						}
					} else {
						//
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}

			}
		});
	}
}
